package com.mrzhou.rabbit.config;

import com.mrzhou.rabbit.constant.RabbitConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author qiang.zhou
 */
@Configuration
@Slf4j
public class RabbitConfiguration {

    @Bean
    public Queue createQueue() {
        return new Queue(RabbitConstant.ELASTICSEARCH_QUEUE, true, false, false);
    }

    @Bean
    public TopicExchange createExchange() {
        return new TopicExchange(RabbitConstant.ELASTICSEARCH_EXCHANGE);
    }

    @Bean
    public Binding bindingExchange() {
        return BindingBuilder.bind(createQueue()).to(createExchange()).with(RabbitConstant.ELASTICSEARCH_QUEUE);
    }


}
